<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>GEN33</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="ScoregensTop.html" title="Score Statements and GEN Routines" />
    <link rel="prev" href="GEN32.html" title="GEN32" />
    <link rel="next" href="GEN34.html" title="GEN34" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">GEN33</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="GEN32.html">Prev</a> </td>
          <th width="60%" align="center">Score Statements and GEN Routines</th>
          <td width="20%" align="right"> <a accesskey="n" href="GEN34.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="GEN33"></a>
      <div class="titlepage"></div>
      <a id="IndexGEN33" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">GEN33</span>
        </h2>
        <p>GEN33 — 
      Generate composite waveforms by mixing simple sinusoids.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp215494384"></a>
        <h2>Description</h2>
        <p>
      These routines generate composite waveforms by mixing simple sinusoids, similarly to <a class="link" href="GEN09.html" title="GEN09"><em class="citetitle">GEN09</em></a>, but the parameters of the partials are specified in an already existing table, which makes it possible to calculate any number of partials in the orchestra.
    </p>
        <p>
      The difference between <span class="emphasis"><em>GEN33</em></span> and <a class="link" href="GEN34.html" title="GEN34"><em class="citetitle">GEN34</em></a> is that <span class="emphasis"><em>GEN33</em></span> uses inverse FFT to generate output, while <span class="emphasis"><em>GEN34</em></span> is based on the algorithm used in oscils opcode. <span class="emphasis"><em>GEN33</em></span> allows integer partials only, and does not support power of two plus 1 table size, but may be significantly faster with a large number of partials. On the other hand, with <span class="emphasis"><em>GEN34</em></span>, it is possible to use non-integer partial numbers and extended guard point, and this routine may be faster if there is only a small number of partials (note that <span class="emphasis"><em>GEN34</em></span> is also several times faster than <a class="link" href="GEN09.html" title="GEN09"><em class="citetitle">GEN09</em></a>, although the latter may be more accurate).
    </p>
      </div>
      <div class="refsect1">
        <a id="idp215560336"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>f</strong></span> # time size  33  src nh scl [fmode]</pre>
      </div>
      <div class="refsect1">
        <a id="idp215562368"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>size</em></span> -- number of points in the table. Must be power of two and at least 4.
    </p>
        <p>
      <span class="emphasis"><em>src</em></span> -- source table number. This table contains the parameters of each partial in the following format:
      </p>
        <div class="literallayout">
          <p><br />
stra, pna, phsa, strb, pnb, phsb, ...<br />
     </p>
        </div>
        <p>

     the parameters are:

     </p>
        <div class="itemizedlist">
          <ul class="itemizedlist" style="list-style-type: disc; ">
            <li class="listitem">
              <p>stra, strb, etc.: relative strength of partials. The actual amplitude depends on the value of scl, or normalization (if enabled).</p>
            </li>
            <li class="listitem">
              <p>pna, pnb, etc.:   partial number, or frequency, depending on fmode (see below); zero and negative values are allowed, however, if the absolute value of the partial number exceeds (size / 2), the partial will not be rendered. With <span class="emphasis"><em>GEN33</em></span>, partial number is rounded to the nearest integer.</p>
            </li>
            <li class="listitem">
              <p>phsa, phsb, etc.: initial phase, in the range 0 to 1.</p>
            </li>
          </ul>
        </div>
        <p>

     Table length (not including the guard point) should be at least 3 * nh. If the table is too short, the number of partials (nh) is reduced to (table length) / 3, rounded towards zero.
    </p>
        <p>
      <span class="emphasis"><em>nh</em></span> -- number of partials. Zero or negative values are allowed, and result in an empty table (silence). The actual number may be reduced if the source table (src) is too short, or some partials have too high frequency.
    </p>
        <p>
      <span class="emphasis"><em>scl</em></span> -- amplitude scale.
    </p>
        <p>
      <span class="emphasis"><em>fmode</em></span> (optional, default = 0) -- a non-zero value can be used to set frequency in Hz instead of partial numbers in the source table.  The sample rate is assumed to be fmode if it is positive, or -(sr * fmode) if any negative value is specified.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp215571984"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the GEN33 routine. It uses the file <a class="ulink" href="examples/gen33.csd" target="_top"><em class="citetitle">gen33.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp215573840"></a>
          <p class="title">
            <strong>Example 1119. Example of the gen33 opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac      <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o gen33.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="oblock">instr</span> 1	<span class="comment">; partials 1, 4, 7, 10, 13, 16, etc. with base frequency of 400 Hz</span>

ibsfrq  <span class="op">=</span>  400										
inumh   <span class="op">=</span>  <span class="opc">int</span>(1.5 <span class="op">+</span> <span class="ohdr">sr</span> <span class="op">*</span> 0.5 <span class="op">/</span> (3 <span class="op">*</span> ibsfrq))					<span class="comment">; estimate number of partials			</span>
isrcln  <span class="op">=</span>  <span class="opc">int</span>(0.5 <span class="op">+</span> <span class="opc">exp</span>(<span class="opc">log</span>(2) <span class="op">*</span> <span class="opc">int</span>(1.01 <span class="op">+</span> <span class="opc">log</span>(inumh <span class="op">*</span> 3) <span class="op">/</span> <span class="opc">log</span>(2))))		<span class="comment">; source table length</span>
itmp    <span class="ohdr">ftgen</span> 1, 0, isrcln, <span class="op">-</span>2, 0						<span class="comment">; create empty source table</span>
ifpos   <span class="op">=</span>  0
ifrq    <span class="op">=</span>  ibsfrq
inumh   <span class="op">=</span>  0
<span class="olabel">l1</span><span class="op">:</span>
        <span class="opc">tableiw</span> ibsfrq <span class="op">/</span> ifrq, ifpos, 1						<span class="comment">; amplitude</span>
        <span class="opc">tableiw</span> ifrq, ifpos <span class="op">+</span> 1, 1						<span class="comment">; frequency</span>
        <span class="opc">tableiw</span> 0, ifpos <span class="op">+</span> 2, 1							<span class="comment">; phase</span>
ifpos   <span class="op">=</span>  ifpos <span class="op">+</span> 3
ifrq    <span class="op">=</span>  ifrq <span class="op">+</span> ibsfrq <span class="op">*</span> 3
inumh   <span class="op">=</span>  inumh <span class="op">+</span> 1
        <span class="octrl">if</span> (ifrq <span class="op">&lt;</span> (<span class="ohdr">sr</span> <span class="op">*</span> 0.5)) <span class="octrl">igoto</span> <span class="olabel">l1</span>

itemp   <span class="ohdr">ftgen</span> 2, 0, 262144, <span class="op">-</span>33, 1, inumh, 1, <span class="op">-</span>1				<span class="comment">; store output in ftable 2 (size = 262144)</span>
asig    <span class="opc">poscil</span> .5, ibsfrq, itemp
        <span class="opc">outs</span> asig, asig 
   
<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="stamnt">i</span> 1 0 2 

<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />

        <span class="phrase">This is the diagram of the waveform generated by GEN33, as used in the example:</span>
    </p>
        <p>
    </p>
        <p>
      </p>
        <div class="mediaobject">
          <img src="images/gen33.png" />
          <div class="caption">
            <p>f 2 0 262144 -33 1 inumh 1 -1</p>
          </div>
        </div>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp215582512"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="GEN09.html" title="GEN09"><em class="citetitle">GEN09</em></a>,
      <a class="link" href="GEN34.html" title="GEN34"><em class="citetitle">GEN34</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp215585552"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Programmer: Istvan Varga</td>
          </tr>
          <tr>
            <td>March 2002</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in version 4.19</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="GEN32.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="ScoregensTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="GEN34.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">GEN32 </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> GEN34</td>
        </tr>
      </table>
    </div>
  </body>
</html>
